package cn.wei.reallyenjoy.common.result;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * @Author: wei
 * @Date: 2021/12/03/17:16

 */
@Data
public class Result implements Serializable {
    private String code;
    private String msg;
    private Object data;
    public static Result succ(Object data) {
        Result m = new Result();
        m.setCode("0");
        m.setData(data);
        m.setMsg("操作成功");
        return m;
    }
    public static Result succ(String mess, Object data) {
        Result m = new Result();
        m.setCode("0");
        m.setData(data);
        m.setMsg(mess);
        return m;
    }

    public static Result fail(String mess) {
        Result m = new Result();
        m.setCode("-1");
        m.setData(null);
        m.setMsg(mess);
        return m;
    }
    public static Result fail(String mess, Object data) {
        Result m = new Result();
        m.setCode("-1");
        m.setData(data);
        m.setMsg(mess);
        return m;
    }
    public static Result succNoData(){
        Result m = new Result();
        m.setCode("0");
        m.setMsg("ok");
        return m;
    }
    public Result succMapData(String key, Object value){
        Map<String,Object> resData= new HashMap<>();
        resData.put(key,value);
        this.setData(resData);
        return this;
    }
}

